import { Approval, ApprovalStatusText } from '../../types/index';
import { getApprovalList } from '../../services/mockData';

Page({
  data: {
    approvalList: [] as Approval[],
    statusText: ApprovalStatusText
  },

  onLoad() {
    this.loadApprovalList();
  },

  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      });
    }
    this.loadApprovalList();
  },

  onPullDownRefresh() {
    this.loadApprovalList();
  },

  async loadApprovalList() {
    const approvalList = await getApprovalList();
    this.setData({ approvalList });
    wx.stopPullDownRefresh();
  },

  goToDetail(e: any) {
    const { id } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/approvalDetail/approvalDetail?id=${id}`
    });
  }
}); 